﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ww.wwf.wwfbll;
using ww.lis.lisbll.sam;
using System.Collections;
using System.IO;

namespace ww.form.lis.sam.jy
{
    public partial class CopyDataForm : ww.form.wwf.SysBaseForm
    { /// <summary>
        /// 逻辑_仪器
        /// </summary>

        string str仪器id = "";
        private JYInstrDataBll bllInstrIO = new JYInstrDataBll();

        private void bllInit()
        {
            try
            {
                //仪器
                InstrBLL bllInstr = new InstrBLL();
                DataTable dtInstr = bllInstr.BllInstrDTByUseAndGroupID(1, ww.wwf.wwfbll.LoginBLL.strDeptID);//仪器列表
                fjy_instrComboBox1.DataSource = dtInstr;
                fjy_instrComboBox2.DataSource = dtInstr;

                //fjy_instrComboBox1.SelectedIndex = fjy_instrComboBox1.FindString(str仪器id);
                //fjy_instrComboBox2.SelectedIndex = fjy_instrComboBox2.FindString(str仪器id);
                fjy_instrComboBox1.SelectedValue = str仪器id;
                fjy_instrComboBox2.SelectedValue = str仪器id;

                //日期
                fjy_dateDateTimePicker1.Value = System.DateTime.Now;
                fjy_dateDateTimePicker2.Value = System.DateTime.Now;
            }
            catch (Exception ex)
            {
                WWMessage.MessageShowError(ex.Message.ToString());
            }
        }

        public CopyDataForm(string _str仪器id)
        {
            InitializeComponent();
            str仪器id = _str仪器id;
        }

        private void buttonTC_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CopyDataForm_Load(object sender, EventArgs e)
        {
            bllInit();
        }

        private void button保存_Click(object sender, EventArgs e)
        {
            string str_msg = "";
            if (ck_copy.Checked)
            {
                str_msg = WWFInit.wwfRemotingDao.DbExecuteScalarBySql(WWFInit.strDBConn, "exec Lis_Ins_Result_CopyMult '" + fjy_instrComboBox1.SelectedValue + "','"
                    + fjy_instrComboBox2.SelectedValue + "','" + fjy_dateDateTimePicker1.Value.ToString("yyyy-MM-dd") + "','" + fjy_dateDateTimePicker2.Value.ToString("yyyy-MM-dd") + "','"
                    + fsample_codeTextBox1.Text.Trim() + "','" + fsample_codeTextBox2.Text.Trim() + "'");
            }
            else
            {
                str_msg = WWFInit.wwfRemotingDao.DbExecuteScalarBySql(WWFInit.strDBConn, "exec Lis_Ins_Result_Copy '" + fjy_instrComboBox1.SelectedValue + "','"
                   + fjy_instrComboBox2.SelectedValue + "','" + fjy_dateDateTimePicker1.Value.ToString("yyyy-MM-dd") + "','" + fjy_dateDateTimePicker2.Value.ToString("yyyy-MM-dd") + "','"
                   + fsample_codeTextBox1.Text.Trim() + "','" + fsample_codeTextBox2.Text.Trim() + "'");
            }
            string[] str = str_msg.Split('|');
            if (str[0] == "1")
                this.DialogResult = DialogResult.OK;
            else
                WWMessage.MessageShowError(str[1]);
        }

        private void fsample_codeTextBox2_Leave(object sender, EventArgs e)
        {
            string fsample_code1 = fsample_codeTextBox1.Text.Trim();
            string fsample_code2 = fsample_codeTextBox2.Text.Trim();

            if (ck_copy.Checked && fsample_code2.Contains("-"))
                return;

            if (fsample_code1=="" || fsample_code2 == "")
                return;

            string[] code1 = fsample_code1.Split('-');
            string[] code2 = fsample_code2.Split('-');
            int begin1, end1, begin2, end2;
            begin1 = Convert.ToInt32(code1[0]);
            end1 = Convert.ToInt32(code1[1]);
            if (end1 < begin1)
            {
                WWMessage.MessageShowError("样本范围1有误，请检查！");
                this.ActiveControl = fsample_codeTextBox1;
                return;
            }
            begin2 = Convert.ToInt32(code2[0]);
            end2 = begin2 + (end1 - begin1);
            fsample_codeTextBox2.Text = begin2.ToString("000") + "-" + end2.ToString("000");
        }

        private void fsample_codeTextBox1_Leave(object sender, EventArgs e)
        {
            string fsample_code1 = fsample_codeTextBox1.Text.Trim();

            if (fsample_code1 == "")
                return;
            string[] code1 = fsample_code1.Split('-');
            int begin1, end1;
            begin1 = Convert.ToInt32(code1[0]);
            if (code1.Length > 1)
                return;
            else
                end1 = begin1;
            fsample_codeTextBox1.Text = begin1.ToString("000") + "-" + end1.ToString("000");
        }
    }
}